home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / RESTRICT.CMM < prev    next >
Text File  |  1994-03-04  |  2KB  |  60 lines

  1. //*****************************************************************
  2. //*** Restrict.cmm - Allow user to only enter commands from the ***
  3. //*** ver.1          list provided here.                        ***
  4. //*****************************************************************
  5.  
  6. Count = 0;
  7. Valid[Count++] = "dir"
  8. Valid[Count++] = "chkdsk"
  9. Valid[Count++] = "type"
  10. Valid[Count++] = "cd"
  11. Valid[Count++] = "set"
  12. Valid[Count++] = "IsItFri"
  13. Valid[Count++] = "DiskFree"
  14.  
  15.  
  16. main()
  17. {
  18.    while ( True ) {  // True is always true, and so this will loop forever
  19.       ShowAvailableCommands()
  20.       Command = GetCommand()
  21.       // check if this command is in our list
  22.       for ( i = 0; i < Count; i++ ) {
  23.          if ( !strcmpi(Command.Root,Valid[i]) )
  24.             break
  25.       }
  26.       if ( i < Count ) {
  27.          system(Command.Full)
  28.       } else {
  29.          // The command was not found
  30.          printf("\"%s\" is not an available command!\a\n",Command.Root)
  31.       }
  32.    }
  33. }
  34.  
  35. ShowAvailableCommands()
  36. {
  37.    printf("\nYour available commands are:\n")
  38.    for ( i = 0; i < Count; i++ )
  39.       printf("%s\t",Valid[i])
  40. }
  41.  
  42. GetCommand()   // Get command from user, return a structure with two elements
  43.                //  .Root   root name of the command entered
  44.                //  .Full   complete line of input as entered
  45. {
  46.    printf("\nWhaddya want? ")
  47.    input.Full = gets()
  48.    // now figure out what the root was, first copy all of input, then remove space from
  49.    // beginning, then go to first space character
  50.    strcpy(input.Root,input.Full)
  51.    // then remove andy whitespace from beginning of command
  52.    while( input.Root[0] != 0  &&  isspace(input.Root[0] ) )
  53.       input.Root++
  54.    // end this string at the first whitespace character
  55.    for ( c = input.Root; c[0] != 0  &&  !isspace(c[0]); c++ ) ;
  56.    c[0] = 0
  57.    return(input)
  58. }
  59.  
  60.